package com.ssm.student.service.impl;

import com.ssm.student.dao.ExaminationTypeMapper;
import com.ssm.student.model.ExaminationType;
import com.ssm.student.service.ExaminationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *实现业务及流程当中的内容
 */
@Service
public class ExaminationTypeServiceImpl implements ExaminationTypeService {
    @Autowired
    private ExaminationTypeMapper examinationTypeMapper;
    @Override
    public int AddExaminationType(ExaminationType examinationType) {
        int returnInt=0;
        /*1.业务判断
        （1）名不能重复

        （1）判断
        * */
        int TestpaperidCount=0;
        TestpaperidCount=examinationTypeMapper.getTypename(examinationType.getExaminationtypeid());
        if (TestpaperidCount<1){
            //2.数据添加
            int addExaminationPapersInt=examinationTypeMapper.insertExaminationType(examinationType);
            //3.返回值设置
            returnInt=addExaminationPapersInt;

        }else {
            returnInt=-1;//有相同的名称
        }
        return returnInt;
    }

    @Override
    public int UpdateExaminationType(ExaminationType examinationType) {
        int isUpdate=0;
        /*1.没有业务流程的判断*/
        try{
            isUpdate=examinationTypeMapper.updateExaminationType(examinationType);
        }catch (Exception e){
            isUpdate=-1;
            //打印更新报错的情况
            System.out.println("更新角色信息时执行SQL报错的原因"+e.getMessage());
        }
        return isUpdate;
    }

    @Override
    public int DeleteExaminationType(int examinationTypesid) {
        int delRole=0;
        /*1.有关业务流程的判断
         * (1)删除的角色不能与人员权限中间表有关联*/
        try {
            //返回的结果总数量小于1才可以删除

        }catch (Exception e){
            delRole=-1;
            System.out.println("删除角色信息时执行SQL报错原因为"+e.getMessage());
        }
        return delRole;
    }
}
